<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class RegisterRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username' => ['required', 'string', 'unique:users,username', 'min:6', 'max:255'],
            'password' => ['required', 'string', 'min:6', 'confirmed'],
            'password_confirmation' => ['required', 'string', 'min:6'],
        ];
    }

    public function messages()
    {
        return [
            'username.required' => '用户名不能为空',
            'username.string' => '用户名必须为字符串',
            'username.unique' => '用户名已存在',
            'username.min' => '用户名长度不能少于6位',
            'username.max' => '用户名长度不能超过255位',
            'password.required' => '密码不能为空',
            'password.string' => '密码必须为字符串',
            'password.min' => '密码长度不能少于6位',
            'password.confirmed' => '两次密码输入不一致',
            'password_confirmation.required' => '确认密码不能为空',
            'password_confirmation.string' => '确认密码必须为字符串',
            'password_confirmation.min' => '确认密码长度不能少于6位',
        ];
    }
}
